var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0}),
    (o.ismfup =
        o.Chapteris完成 =
        o.Chapteris解锁 =
        o.c分数和状态 =
        o.cloneAdata =
        o.getAllFall =
        o.randomFall =
        o.getRdata =
        o.Adata =
        o.getHeroNextLv =
        o.getSkillBuff =
        o.getSkillLv =
        o.getDisEnemy =
        o.getRectHas =
        o.getStateData =
        o.forEachSlots =
        o.showEquip =
        o.showEquips =
        o.getzdl =
        o.getEquipsPars =
        o.getupmoney =
        o.getHeroLv =
        o.getHeroPars =
        o.getView =
        o.getbuildbody =
        o.distance =
            void 0);
var n = t("GameData"),
    r = t("Util"),
    a = t("Platforms"),
    i = t("ConfS"),
    s = t("body"),
    c = t("build");
function l(t, e) {
    return cc.Vec2.distance({x: t.node.x, y: t.node.y}, {x: e.node.x, y: e.node.y});
}
(o.distance = l),
    (o.getbuildbody = function (t) {
        return 1 == t.tag ? t.getComponent(c.default) : t.getComponent(s.default);
    }),
    (o.getView = function (t) {
        return cc.find("Canvas/View").getComponent(t);
    });
function u(t, e) {
    var o = 1e3 * (t - 112e6) + e + 124e6;
    return i.DatasManager.UpgradeDatasById[o];
}
function p(t, e) {
    var o = e ? e[t] : n.default.herolvs[t];
    return null == o && (o = 1), o;
}
function f(t, e) {
    null == e && (e = n.default.equips);
    for (var o = 0, r = 0, a = 0, s = 0; s < t.equipids.length; s++) {
        var c = t.equipids[s];
        if (e.includes(c)) {
            var l = i.DatasManager.EquipDatasById[c];
            (o += l.attack), (r += l.defense), (a += l.HP);
        }
    }
    return {a: o, d: r, h: a};
}
function d(t, e) {
    h(t, e.Slots, e.Slotimgs, function (t, e) {
        t.setAttachment(e);
    });
}
function h(t, e, o, n) {
    for (var r in e) {
        var a = e[r],
            i = o[r],
            s = t.getAttachment(a, i),
            c = t.findSlot(a);
        if (!c || !s) throw new Error("零件出错:[slot-" + a + "][img-" + i + "]");
        n(c, s);
    }
}
function y(t, e) {
    var o = e ? e[t] : n.default.skillLvs[t];
    return null == o && (o = 1), o || 0;
}
(o.getHeroPars = u),
    (o.getHeroLv = p),
    (o.getupmoney = function (t) {
        var e = 1e3 * (t - 112e6) + 124e6 + p(t);
        return i.DatasManager.UpgradeDatasById[e];
    }),
    (o.getEquipsPars = f),
    (o.getzdl = function (t, e, o, n) {
        var r = p(t.ID, n),
            a = u(t.ID, r),
            i = a.attack,
            s = a.defence,
            c = a.hp,
            l = a.Cirt,
            d = a.Block,
            h = f(t, e);
        (i += h.a), (s += h.d);
        for (
            var g = 12 * i * (1 + l / 1e4) + (1 * (c += h.h) + 12 * s) * (1 + d / 1e4), v = 0;
            v < t.skills.length;
            v++
        )
            g += 500 * y(t.skills[v], o);
        return Math.round(g);
    }),
    (o.showEquips = function (t, e, o) {
        null == o && (o = n.default.equips),
            e.equipids.forEach(function (e) {
                o.includes(e) && d(t, i.DatasManager.EquipDatasById[e]);
            });
    }),
    (o.showEquip = d),
    (o.forEachSlots = h),
    (o.getStateData = function (t, e) {
        for (var o = i.DatasManager.StateDatas, n = 0; n < o.length; n++) {
            var r = o[n];
            if (r.HeroID == t && r.ActionName == e) return r;
        }
    }),
    (o.getRectHas = function (t, e, o, n) {
        for (var r = [], a = 0; a < n.length; a++) {
            var i = n[a];
            Math.abs(i.node.x - t.node.x) < e && Math.abs(i.node.y - t.node.y) < o && r.push(i);
        }
        return r;
    }),
    (o.getDisEnemy = function (t, e) {
        for (var o = 1 / 0, n = null, r = 0; r < e.length; r++) {
            var a = e[r],
                i = l(t, a);
            null == n ? ((o = i), (n = a)) : i < o && ((o = i), (n = a));
        }
        return n;
    }),
    (o.getSkillLv = y),
    (o.getSkillBuff = function (t, e) {
        var o = 100 * (t - 101e6) + (e || y(t)) + 1e8;
        return i.DatasManager.BuffDatasById[o];
    }),
    (o.getHeroNextLv = function (t) {
        return u(t, p(t) + 1);
    });
var g = (function () {
    return function () {
        (this.skilllvs = {}), (this.equips = []), (this.herolvs = {});
    };
})();
function v(t) {
    for (var e = [], o = 1, n = 109e6 + 100 * t + o, r = i.DatasManager.FallDatasById[n]; r; )
        e.push(r), (n = 109e6 + 100 * t + ++o), (r = i.DatasManager.FallDatasById[n]);
    return e;
}
(o.Adata = g),
    (o.getRdata = function (t) {
        for (var e = 0, o = 0, s = 0; s < n.default.heros.length; s++) {
            var c = n.default.heros[s],
                l = p(c);
            e < l && ((e = l), (o = c));
        }
        var u = new g(),
            f = i.DatasManager.HeroDatas,
            d = f[r.RandomInt(0, f.length - 1)];
        u.data = d;
        var h = 0;
        if (t < 2) {
            var v = Math.round(i.DatasManager.PVP匹配调整1 * e);
            (h = e + (v *= r.isRandom(0.5) ? 1 : -1)) < 1 && (h = 1), h > 50 && (h = 50), (u.herolvs[d.ID] = h);
        } else
            (v = 0.1 + Math.random() * (i.DatasManager.PVP匹配调整2 - 0.1)),
                (h = Math.round(e * v)) < 1 && (h = 1),
                h > 50 && (h = 50),
                (u.herolvs[d.ID] = h);
        u.equips.push(d.equipids[0]), u.equips.push(d.equipids[1]), u.equips.push(d.equipids[2]);
        for (var m = 1, A = i.DatasManager.HeroDatasById[o].equipids, b = 0; b < A.length; b++) {
            var C = A[b],
                w = y(i.DatasManager.EquipDatasById[C].jineng);
            w < m && (m = w);
        }
        return (
            (u.skilllvs[d.equipids[0]] = m),
            (u.skilllvs[d.equipids[1]] = m),
            (u.skilllvs[d.equipids[2]] = m),
            (u.type = r.isRandom(0.2) ? 0 : 1),
            u.type
                ? (u.count = r.RandomInt(i.DatasManager.PVP金币奖励[0], i.DatasManager.PVP金币奖励[1]))
                : (u.count = r.RandomInt(i.DatasManager.PVP钻石奖励[0], i.DatasManager.PVP钻石奖励[1])),
            (u.fall = 9999),
            (u.gailv = 1),
            (u.name = r.randomArray(i.DatasManager.NameDatas).Name),
            "4399小游戏" == a.default.platformType && (u.name = "4399玩家" + _()),
            u
        );
    }),
    (o.randomFall = function (t) {
        var e = v(t),
            o = 0;
        e.forEach(function (t) {
            o += t.chance;
        });
        var n = r.RandomInt(0, o),
            a = 0,
            i = 0,
            s = e[i];
        for (a += s.chance; n > a; ) a += (s = e[++i]).chance;
        return s;
    }),
    (o.getAllFall = v),
    (o.cloneAdata = function (t) {
        var e = new g(),
            o = r.randomArray(i.DatasManager.HeroDatas);
        (e.data = o),
            (e.herolvs[o.ID] = t.herolvs[t.data.ID]),
            e.equips.push(o.equipids[0]),
            e.equips.push(o.equipids[1]),
            e.equips.push(o.equipids[2]);
        var n = t.skilllvs[t.data.skills[0]];
        return (
            (e.skilllvs[o.equipids[0]] = n),
            (e.skilllvs[o.equipids[1]] = n),
            (e.skilllvs[o.equipids[2]] = n),
            (e.fall = 9999),
            (e.gailv = 1),
            (e.name = r.randomArray(i.DatasManager.NameDatas).Name),
            "4399小游戏" == a.default.platformType && (e.name = "4399玩家" + _()),
            e
        );
    });
var m = 0;
function _() {
    return ++m > 9 && (m = 0), m;
}
var A = (function () {
    return function () {
        (this.name = "name"), (this.isplayer = !1), (this.isdie = !1), (this.num = 0);
    };
})();
(o.c分数和状态 = A),
    (o.Chapteris解锁 = function (t) {
        if (t.UnlockChapter) return !0;
        var e = i.DatasManager.ChapterDatasById[t.UnlockChapterId].chapterList,
            o = e[e.length - 1];
        return !!n.default.fubens.includes(o);
    }),
    (o.Chapteris完成 = function (t) {
        var e = t.chapterList,
            o = e[e.length - 1];
        return !!n.default.fubens.includes(o);
    }),
    (o.ismfup = function () {
        var t = 0,
            e = n.default.herolvs;
        for (var o in e) (t += e[o]), t--;
        var r = t % i.DatasManager.看视频升级出现频率.length;
        return i.DatasManager.看视频升级出现频率[r];
    });
